package cn.edu.ctbu.kcsj.service.impl;

import cn.edu.ctbu.kcsj.domain.Score;
import cn.edu.ctbu.kcsj.repository.ScoreRepository;
import cn.edu.ctbu.kcsj.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreImplService implements ScoreService {
    @Autowired
    private ScoreRepository scoreRepository;
    public  List<Score> findAll() {
        return scoreRepository.findAll();
    }
    /**
     * 只分页的查询
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Pageable pageable){
        return scoreRepository.findAll(pageable);
    }
    /**
     * 分页，带过滤的查询
     * @param score
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Example<Score> score, Pageable pageable){
        return scoreRepository.findAll(score,pageable);
    }
    public Score insert(Score score){

        return scoreRepository.save(score);
    }
    public Score update(Score score){
        return scoreRepository.save(score);
    }
    public Score getBySid(Integer sid){
        Score score=scoreRepository.findById(sid).orElse(null);
        return score;
    }
    public void delete(Integer sid){
        Score score=new Score();
        score.setSid(sid);
        scoreRepository.delete(score);
    }
}
